<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.style1 {
	width: 400px;
	margin: 0px auto;
	margin-bottom: 20px;
	border: 1px solid #96C2F1;
	background-color: #EFF7FF
}
</style>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/topic_choose_template.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/json2.js"></script>
<script type="text/javascript">
	var data =null;
	var page=null;
	var topicsList = null;
	$(document).ready(function() {
		query();
	});

	function query() {
		$.ajax({
			type : "POST",
			url : "/itembank/Action!TopicAction_getTopics.go",
			data : {
				"page" : JSON.stringify(page)
			},
			dataType : "json",
			success : function(data, textStatus) {
				page = data.page;
				topicsList = data.datas;
				buttonCtrl(page);
				$("#topic").fadeOut("slow",function(){
					$("#topic").empty();
					$(topicsList.topics).each(function(i,topic){
						topic_choose_create(topic,page,i);
					});
					$("#topic").fadeIn("slow");
						$("#totalTopic").	html(page.totalRow);
				});
			},
			error : function(msg) {
				alert("error!");
			}
		});
	}

	function buttonCtrl(page){
		createPage();
		if((page.currentPage*page.rowPerPage)>=page.totalRow){
			$("#nextButton").attr("disabled",true);
		}else{
			$("#nextButton").removeAttr("disabled");
		}
		if(page.currentPage==1){
			$("#preButton").attr("disabled",true);
		}else{
			$("#preButton").removeAttr("disabled");
		}
	}
	
	function nextpage() {
		page.currentPage++;
		query();
	}

	function prepage() {
		page.currentPage = page.currentPage - 1;
		query();
	}
	
	function createPage(){
		var pageTable = $("#page");
		pageTable.empty();
		var nextButton = $("<input id='nextButton' type='button'  value='下一题' onclick='nextpage()'>")
//		var preButton = $("<input id='preButton' type='button'  value='上一组' onclick='prepage()'>")
		var total = $("<a>总共有<span id='totalTopic'>  </span>道试题</a>")
		pageTable.append(total);
//		pageTable.append(preButton);
		pageTable.append(nextButton);
	}
</script>
</head>
<body>
	<table id="tab">
		<tr id="tab_tr">
			<td id="topics">
				<table id="topic">

				</table>
			</td>
		</tr>
		<tr><td id="page"></td></tr>
	</table>
	<div></div>
</body>
</html>